package com.app.manage.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Rsp<T> {
    private String code;
    private String msg;
    private T data;

    public boolean isSuccess() {
        return "0000".equals(this.code);
    }

    public static <T> Rsp<T> success() {
        return Rsp.success(null);
    }

    public static <T> Rsp<T> success(T data) {
        return new Rsp<>("0000", "请求成功", data);
    }

    public static <T> Rsp<T> fail() {
        return Rsp.fail("9999", "请求失败");
    }

    public static <T> Rsp<T> fail(String msg) {
        return Rsp.fail("9999", msg);
    }

    public static <T> Rsp<T> fail(String code, String msg) {
        return new Rsp<>(code, msg, null);
    }
}
